﻿using System;

namespace Graphe.Collations.Commands
{
    public class RemoveFromCollectionCommand<T> : Command
    {
        #region Constructor

        public RemoveFromCollectionCommand(T element, ICollationCollection<T> collection)
        {
            _element = element;
            _collection = collection;
        }

        #endregion
        #region Private Instance Fields

        private T _element;
        private ICollationCollection<T> _collection;
        private int _indexOfItem;

        #endregion

        public override void Execute()
        {
            _indexOfItem = _collection.IndexOf(_element);
            _collection.Remove(_element);
        }

        public override void Undo()
        {
            _collection.Insert(_indexOfItem, _element);
        }
    }
}
